<!--#include file="easyasp/easp.asp" -->
<!--#include file="easyasp/plugin/ea1.asp" -->
<script language="JScript" runat="Server">
    function ToObject(json) {
        var o;
        eval("o=" + json);
        return o;
    }

    function toArray(s) {
        var dic = Server.CreateObject("Scripting.Dictionary")
        eval("var a=" + json);
        for (var i = 0; i < a.length; i++) {
            var obj = Server.CreateObject("Scripting.Dictionary")
            for (x in a[i]) obj.Add(x, a[i][x])
            dic.Add(i, obj);
        }
        return dic
    }
</script>
<%
	' easp.db.exec("ALTER TABLE [user] ADD [user_typ] NVARCHAR (40) NULL")
	' easp("my").d2v "select name2 from [baseinfo] where [name1]='网站标题'","webtitle"
dim filepath2,GetUrl,delimiter,lf
delimiter="|"
filepath2= Server.MapPath("\")
const rootpath="dzps"
lf=chr(13)&chr(10)
Easp.NoCache
GetUrl=Easp.GetUrl("")
'echo GetUrl
if  Easp.Str.IsIn(GetUrl, "website.asp") or Easp.Str.IsIn(GetUrl, "index.asp") or Easp.Str.IsIn(GetUrl, "login.asp") or Easp.Str.IsIn(GetUrl, "user/reg.asp") then
	binfo
end if

't_define

dim action1
action1=val("action")
if action1="numb" then
	numb	
elseif action1="qx_save2" then
	qx_save2
end if
  function badge(txt,bg)
    badge="<span class='layui-badge-rim layui-bg-blue'>"&txt&"</span>"
    if bg="" then
      badge=replace(badge,"layui-bg-blue",bg)
    else
      badge=replace(badge,"blue",bg)
    end if
  end function
function colla(title,content)
	dim txt
	txt=txt&  "<div class='layui-colla-item'>"
    txt=txt&  "<h2 class='layui-colla-title'>"& title &"</h2>"  
    txt=txt&  "<div class='layui-colla-content'>"
    txt=txt&  content
    txt=txt& "</div>"
	txt=txt& "</div>"	
	colla=txt				
end function

function colla2(title,content)
	dim txt
	'txt=txt&  "<div class='layui-colla-item'>"
    'txt=txt&  "<h2 class='layui-colla-title'>"& title &"</h2>"  
    'txt=txt&  "<div class='layui-colla-content'>"
    txt=txt&  content
    'txt=txt& "</div>"
	'txt=txt& "</div>"	
	colla2=txt				
end function

  function input1(fieldn,label,required1)
    if required1="1" then
      required1="required"
    end if
    Echo myjs2("input1.html","fieldn~"&fieldn&",label~"&label&",value~"&val(fieldn)&",required::~"&required1,"~")
  end function
  function button1(fieldn,label,value1)
    Echo myjs1("button1.html","fieldn|"&fieldn&",label|"&label&",value|"&value1)
  end function 
Function myjs2(fn,mb,flag) 
	dim txt,amb,i,amb_xm
	txt=myr(fn)
	amb=split(mb,",")
	for i=0 to ubound(amb)
		amb_xm=split(amb(i),flag)
		if ubound(amb_xm)>=1 then
			if replace(amb_xm(0),"::","")<>amb_xm(0) then
				amb_xm(0)=replace(amb_xm(0),"::","")
				txt=replace(txt,amb_xm(0),amb_xm(1))
			else
				txt=replace(txt,hr_dy(amb_xm(0)),amb_xm(1))	
			end if
		end if
	next
	myjs2=txt
End Function
Function txtarea0(param)
	txtarea0 = myjs1("textarea_no_label.html",param)
	echo txtarea0
End Function
Function ta0(name,value)
	ta0 = myjs1("textarea_no_label.html","fieldn|"&name& ","&"value|"&value)
	echo ta0
End Function
Function myjs1(fn,mb) 
	dim txt,amb,i,amb_xm
	txt=myr(fn)
	amb=split(mb,",")
	for i=0 to ubound(amb)
		amb_xm=split(amb(i),delimiter)
		if ubound(amb_xm)>=1 then
			if replace(amb_xm(0),"::","")<>amb_xm(0) then
				amb_xm(0)=replace(amb_xm(0),"::","")
				txt=replace(txt,amb_xm(0),amb_xm(1))
			else
				txt=replace(txt,hr_dy(amb_xm(0)),amb_xm(1))	
			end if
		end if
	next
	myjs1=txt
End Function
Function myjs1_de(fn,mb) 
	dim txt,amb,i,amb_xm
	txt=myr(fn)
	amb=split(mb,",")
	for i=0 to ubound(amb)
		amb_xm=split(amb(i),"|lse|")
		if ubound(amb_xm)>=1 then
			if replace(amb_xm(0),"::","")<>amb_xm(0) then
				amb_xm(0)=replace(amb_xm(0),"::","")
				txt=replace(txt,amb_xm(0),amb_xm(1))
			else
				txt=replace(txt,hr_dy(amb_xm(0)),amb_xm(1))	
			end if
		end if
	next
	myjs1=txt
End Function

Function js4(fn,tn,title,zdy1,zdy1_title) 
	dim txt
	txt=myr(fn)
	txt=replace(txt,"[dy:tn]",tn)
	txt=replace(txt,"[dy:title]",title)
	txt=replace(txt,"[dy:zdy1]",zdy1)
	txt=replace(txt,"[dy:zdy1_title]",zdy1_title)
	js4=txt
End Function
	
Function txtarea1(fieldn,label,lay_verify)
	if lay_verify="1" then
		lay_verify="required"
	end if
	echo js2("textarea.html",fieldn,label,val(fieldn),lay_verify)
End Function
Function js2(fn,fieldn,label,val,lay_verify) 
	dim txt
	txt=myr(fn)
	txt=replace(txt,"[dy:fieldn]",fieldn)
	txt=replace(txt,"[dy:label]",label)
	txt=replace(txt,"[dy:value]",val)
	txt=replace(txt,"required",lay_verify)
	js2=txt
	' Easp.Echo txt
End Function

Function js1(fn,tn,title) 
	dim txt
	txt=myr(fn)
	txt=replace(txt,"[dy:tn]",tn)
	txt=replace(txt,"[dy:title]",title)
	js1=txt
	' Easp.Echo txt
End Function

Function btn0(tn,title)
	btn0=js1("btn0.html",tn,title)
	echo btn0
End Function

Function btn0_s(tn,title)
	btn0_s=js1("btn0_s.html",tn,title)
	echo btn0_s
End Function

Function btn0_xs(tn,title)
	btn0_xs=js1("btn0_xs.html",tn,title)
	echo btn0_xs
End Function

Function rc(sql)
	dim rs
	Set Rs = Easp.Db.Sel(sql)
	if rs.RecordCount>=1 then
		rc=rs.RecordCount
	else
		rc=0
	end if
	rs.close
	Set rs = Nothing
End Function
Function s1(sql)
	s1=s11(sql,"")
End Function

Function s11(sql,varname)
	dim rs,x
	set rs=easp.db.sel(sql)
	if rs.RecordCount>=1 then
		for each x in rs.fields
			easp.var(x.name)=x.value
		next
	end if	
	s11=val(varname)
End Function
function scw(txt,cw)
	dim l
	l=len(cw)
	scw= left(txt,len(txt)-l)
end function
Function hr_bd(txt)
	hr_bd="bd[" & txt & "]"
End Function

Function s11_2(sql)
	dim rs,x
	set rs=easp.db.sel(sql)
	if rs.RecordCount>=1 then
		for each x in rs.fields
			easp.var(hr_bd(x.name))=x.value
		next
	end if	
End Function

Function RegExpTest2(patrn, strng) 
	Dim regEx, Match, Matches,RetStr 
	Set regEx = New RegExp 
	regEx.Pattern = patrn 
	regEx.IgnoreCase = True ' 设置是否区分大小写。 
	regEx.Global = True ' 设置全程可用性。 
	Set Matches = regEx.Execute(strng) 
	For Each Match in Matches
		RetStr = RetStr & Match.FirstIndex & "|" 
		RetStr = RetStr & Match.value
	Next 
	RegExpTest2 = RetStr 
End Function 

Function ReplaceTest(str,patrn, replStr) 
	Dim regEx, str1 ' 建立变量。 
	'str1 = "dog 123." 
	Set regEx = New RegExp ' 建立正则表达式。 
	RegEx.Global = True 
	regEx.Pattern = patrn ' 设置模式。 
	regEx.IgnoreCase = True ' 设置是否区分大小写。 
	ReplaceTest = regEx.Replace(str, replStr) ' 作替换。 
End Function 

Function RegExpTest(patrn, strng) 
	Dim regEx, retVal ' 建立变量。 
	Set regEx = New RegExp ' 建立正则表达式。 
	regEx.Pattern = patrn ' 设置模式。 
	regEx.IgnoreCase = False ' 设置是否区分大小写。 
	retVal = regEx.Test(strng) ' 执行搜索测试。 
	If retVal Then 
	RegExpTest = "找到一个或多个匹配。" 
	Else 
	RegExpTest = "未找到匹配。" 
	End If 
End Function 

Function ret1(ret)
	if ret>=1 then
		easp.echo "0"
	else
		easp.echo "1"
	end if
End Function
Function ret2(ret)
	if ret>=1 then
		retJson "0","成功",""
	else
		retJson "1","失败",""
	end if
End Function
Function execsqlret(ret,msg)
	if ret>=1 then
		if msg="" then
			msg="成功"
		end if
		retJson "0",msg,""
	else
		if msg="" then
			msg="失败"
		end if
		retJson "1",msg,""
	end if
End Function
Function rt(ret)
	execsqlret ret,""
End Function
Function rt2(ret,msg)
	execsqlret ret,msg
End Function
Function ret3(ret)
	if ret="1" then
		easp.echo "1"
	else
		easp.echo ret
	end if
End Function

Function ws(tn,field,value1)
	dim fielda,s,i,value1a
	fielda=split(field,",")
	value1a=split(value1,",")
	for i=0 to ubound(fielda)
		fielda(i)=replace(fielda(i),"[","")
		fielda(i)=replace(fielda(i),"]","")
		if right(fielda(i))=":" then
			fielda(i)=replace(fielda(i),":","")
			s=s+fielda(i)+"="+value1a(i)+","	
		else
			s=s+fielda(i)+"="+da(value1a(i))+" and "	
		end if
	next
	s=left(s,len(s)-5)
	ws=s
End Function
Function cr2(tn,field)
    dim fielda,s,i
	fielda=split(field,",")
	s="insert into " & tn & xkh(field) & " values ("
	for i=0 to ubound(fielda)
		fielda(i)=replace(fielda(i),"[","")
		fielda(i)=replace(fielda(i),"]","")
		
		if val(hr_1(fielda(i))) = "" then
			s=s+dkh(fielda(i))+","		
		else
			s=s+dkh(hr_1(fielda(i)))+","
		end if
	next
	s=left(s,len(s)-1) & ")"
	cr2=s
End Function

Function cr(tn,field)
    dim fielda,s,i
	fielda=split(field,",")
	s="insert into " & tn & xkh(field) & " values ("
	for i=0 to ubound(fielda)
		fielda(i)=replace(fielda(i),"[","")
		fielda(i)=replace(fielda(i),"]","")
		s=s+dkh(fielda(i))+","
	next
	s=left(s,len(s)-1) & ")"
	cr=s
End Function
Function hr_1(txt)
	hr_1="field[" & txt & "]"
End Function

Function hr_2(txt)
	hr_2="field[" & txt & "]"
End Function
Function hr_data(txt)
	hr_data="data[" & txt & "]"
End Function
Function hr_dy(txt)
	hr_dy="[dy:" & txt & "]"
End Function
Function execsw(sqla)
	dim result,i
	if not isArray(sqla) then
		result=easp.db.query(sqla)
		if result then
			execsw=1
		else
			execsw=0
		end if
	else
		easp.db.begin
		' sqla=split(sqls,";")
		for i=0 to ubound(sqla)
			if sqla(i)<>"" then
				result=easp.db.query(sqla(i))
				if not result then
					exit for
				end if
			end if
		next 
		if i<=ubound(sqla) then
			easp.db.RollBack
			execsw=0
		else
			easp.db.Commit
			execsw=1
		end if
	end if
End Function

Function retJson(code,msg,data)
	Easp.Echo "{" & syh("code") & ":"&code&","  & syh("msg") & ":" & syh(msg) & "," & syh("data") & ":[" & data & "]"&"}"
End Function

Function qry2json(sql)
	dim rs,rsjson,json,s
	dim a,b
	if val("limit")="" then
		vas "limit",10
	end if
	easp.db.pagesize = easp.var("limit")
	set rs  = Easp.Db.GetRs(sql)
	Easp.Json.EncodeUnicode=false
	rsjson=Easp.Encode(rs)
	Easp.Db.Close(rs)
	set json=Easp.Decode(rsjson)
	json.put "total",easp.db.pagerecordcount

	s = json.toString()
	a =  instr(s,"[")
	b =  instr(s,"]")
	s = replace(s,"rows","data")
	s = replace(s,"total","count")
	s = replace(s, chr(34)&"true"& chr(34),"true")
	
	Easp.Echo replace(s,"{",  "{" & syh("code") & ":0,"  & syh("msg") & ":" & syh("success") & ",",1,1)
	set json = nothing
End Function
	
Function syh(txt)
	txt = chr(34)&txt&chr(34)
	syh=txt
End Function

Function da(txt)
	txt = chr(39)&txt&chr(39)
	da=txt
End Function

Function lbfh(txt)
	txt=da("%"&txt&"%")
	lbfh=" like " & txt
End Function

Function bfh(txt)
	txt=da("%"&txt&"%")
	bfh=txt
End Function

Function dkh(txt)
	txt="{"&txt&"}"
	dkh=txt
End Function

Function zkh(txt)
	txt="["&txt&"]"
	zkh=txt
End Function

Function frmp(txt)
	txt="data" & zkh(txt)
	frmp=txt
End Function

Function xkh(txt)
	txt="("&txt&")"
	xkh=txt
End Function

Function daj(txt)
	txt = "#" & txt& "#"
	daj=txt
End Function

Function xg(tn,field,w)
    dim fielda,s,i
	fielda=split(field,",")
	s="update " & tn &" set "
	for i=0 to ubound(fielda)
		s=s+fielda(i)
		fielda(i)=replace(fielda(i),"[","")
		fielda(i)=replace(fielda(i),"]","")
		s=s+"="+dkh(fielda(i))+","
	next
	s=left(s,len(s)-1) 
	xg=s+" where "+w
End Function

Function xg2(tn,field,w)
    dim fielda,s,i
	fielda=split(field,",")
	s="update " & tn &" set "
	for i=0 to ubound(fielda)
		s=s+fielda(i)
		fielda(i)=replace(fielda(i),"[","")
		fielda(i)=replace(fielda(i),"]","")
		if val(hr_1(fielda(i))) = "" then
			s=s+"="+dkh(fielda(i))+","
		else
			s=s+"="+dkh(hr_1(fielda(i)))+","
		end if

	next
	s=left(s,len(s)-1) 
	xg2=s+" where "+w
	' echo xg2
End Function

'==================================================================建库
sub createdatabase()
	dim DBName,dbstr,myCat
	on error resume next
	DBName = request("dataname")
	dbstr = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & DBName 
	Set myCat = Server.CreateObject( "ADOX.Catalog" ) 
	myCat.Create dbstr
	
	if err <> 0 then
		response.write err.description
		session("dbtype") = ""
		session("dbstr") = ""
		response.write "<input type='button' name='ok' value=' 返 回 ' onClick='javascript:history.go(-1)'>"
		response.end
	end if
	
	session("dbtype") = "access"
	session("dbstr") = dbstr
	response.redirect "?"
end sub	
function conn2()
	vas "dbName",session("dbName")
	Easp.Db.SetConnection "conn2", "ACCESS", "/dzps/dbs/"&val("dbName")&".mdb", ""
	Set conn2 =  Easp.Db.GetConnection("conn2")
end function
function conn()
	dim conn1,connstr
	on error resume next
	select case session("dbtype")
	case "access"
		'==================================================================连接ACCESS数据库
		connstr = session("dbstr")
		Set Conn1 = Server.CreateObject("ADODB.Connection")
		conn1.Open connstr
	case "sql"
		'==================================================================连接SQL数据库
		set conn1 = Server.CreateObject("ADODB.Connection") 
		conn1.open session("dbstr") 
	end select
	
	if err <> 0 then
		response.write err.description
		session("dbtype") = ""
		session("dbstr") = ""
		response.write "<input type='button' name='ok' value=' 返 回 ' onClick='javascript:history.go(-1)'>"
		response.end
	end if
	set conn = conn1
end function

Sub echo(str)
	Response.Write(str)
End Sub

Function IIf(var, val1, val2)
	If var = True Then
		IIf = val1
	 Else
		IIf = val2
	End If
End Function

'正则表达式函数，用于删除注释
'-------------------------------------
Function RegExpReplace(strng, patrn, replStr)
  Dim regEx,match,matches              ' 建立变量。
  Set regEx = New RegExp               ' 建立正则表达式。
  regEx.Pattern = patrn               ' 设置模式。
  regEx.IgnoreCase = True               ' 设置是否区分大小写。
  regEx.Global = True   ' 设置全局可用性。

  RegExpReplace = regEx.Replace(strng, replStr)         ' 作替换。
End Function

'==================================================================ADOVBS 常量声明

'---- DataTypeEnum Values ----
Const adEmpty = 0
Const adTinyInt = 16
Const adSmallInt = 2
Const adInteger = 3
Const adBigInt = 20
Const adUnsignedTinyInt = 17
Const adUnsignedSmallInt = 18
Const adUnsignedInt = 19
Const adUnsignedBigInt = 21
Const adSingle = 4
Const adDouble = 5
Const adCurrency = 6
Const adDecimal = 14
Const adNumeric = 131
Const adBoolean = 11
Const adError = 10
Const adUserDefined = 132
Const adVariant = 12
Const adIDispatch = 9
Const adIUnknown = 13
Const adGUID = 72
Const adDate = 7
Const adDBDate = 133
Const adDBTime = 134
Const adDBTimeStamp = 135
Const adBSTR = 8
Const adChar = 129
Const adVarChar = 200
Const adLongVarChar = 201
Const adWChar = 130
Const adVarWChar = 202
Const adLongVarWChar = 203
Const adBinary = 128
Const adVarBinary = 204
Const adLongVarBinary = 205

'---- FieldAttributeEnum Values ----
Const adFldMayDefer = &H00000002
Const adFldUpdatable = &H00000004
Const adFldUnknownUpdatable = &H00000008
Const adFldFixed = &H00000010
Const adFldIsNullable = &H00000020
Const adFldMayBeNull = &H00000040
Const adFldLong = &H00000080
Const adFldRowID = &H00000100
Const adFldRowVersion = &H00000200
Const adFldCacheDeferred = &H00001000

'---- SchemaEnum Values ----
'---- SchemaEnum Values ----
Const adSchemaProviderSpecific = -1
Const adSchemaAsserts = 0
Const adSchemaCatalogs = 1
Const adSchemaCharacterSets = 2
Const adSchemaCollations = 3
Const adSchemaColumns = 4
Const adSchemaCheckConstraints = 5
Const adSchemaConstraintColumnUsage = 6
Const adSchemaConstraintTableUsage = 7
Const adSchemaKeyColumnUsage = 8
Const adSchemaReferentialConstraints = 9
Const adSchemaTableConstraints = 10
Const adSchemaColumnsDomainUsage = 11
Const adSchemaIndexes = 12
Const adSchemaColumnPrivileges = 13
Const adSchemaTablePrivileges = 14
Const adSchemaUsagePrivileges = 15
Const adSchemaProcedures = 16
Const adSchemaSchemata = 17
Const adSchemaSQLLanguages = 18
Const adSchemaStatistics = 19
Const adSchemaTables = 20
Const adSchemaTranslations = 21
Const adSchemaProviderTypes = 22
Const adSchemaViews = 23
Const adSchemaViewColumnUsage = 24
Const adSchemaViewTableUsage = 25
Const adSchemaProcedureParameters = 26
Const adSchemaForeignKeys = 27
Const adSchemaPrimaryKeys = 28
Const adSchemaProcedureColumns = 29
Const adSchemaDBInfoKeywords = 30
Const adSchemaDBInfoLiterals = 31
Const adSchemaCubes = 32
Const adSchemaDimensions = 33
Const adSchemaHierarchies = 34
Const adSchemaLevels = 35
Const adSchemaMeasures = 36
Const adSchemaProperties = 37
Const adSchemaMembers = 38
Const adSchemaTrustees = 39
Const adSchemaFunctions = 40
Const adSchemaActions = 41
Const adSchemaCommands = 42
Const adSchemaSets = 43

Function col(field_name)
	dim rs
	easp.var("fld")=field_name
	Set rs = Easp.Db.Sel("select * from bi0 where trim(fld)={fld} and dbName={dbName}")
	col=rs("colName")
End Function

Function col2()
	dim rs,a,i,arr
	Set a= CreateObject("Scripting.Dictionary")
	Set rs = Easp.Db.Sel("select fld,colName from bi0 where dbName={dbName}")
	if rs.recordCount >=1 then
		arr = rs.getrows
		set session("mydict")=Server.CreateObject("Scripting.Dictionary") 
		for i=0 to ubound(arr,2)
			session("mydict").add trim(arr(0,i)),arr(1,i)
		next
	end if
	col2=arr '返回数组
End Function

Function mem(field_name)
	dim rs
	easp.var("fld")=field_name
	Set rs = Easp.Db.Sel("select * from bi0 where trim(fld)={fld} and dbName={dbName}")
	mem=rs("mm1")
End Function

Function mem_blank(id)
	dim rs
	easp.var("id")=id
	Set rs = Easp.Db.Sel("select * from bi0 where id={id}")
	mem=rs("mm1")
End Function

'==================================================================返回字段类型函数
Function typ(field_type)
	'field_type = 字段类型值
	Select Case field_type
		case adEmpty:typ = "Empty"
		case adTinyInt:typ = "TinyInt"
		case adSmallInt:typ = "SmallInt"
		case adInteger:typ = "Integer"
		case adBigInt:typ = "BigInt"
		case adUnsignedTinyInt:typ = "TinyInt" 'UnsignedTinyInt
		case adUnsignedSmallInt:typ = "UnsignedSmallInt"
		case adUnsignedInt:typ = "UnsignedInt"
		case adUnsignedBigInt:typ = "UnsignedBigInt"
		case adSingle:typ = "Single" 'Single
		case adDouble:typ = "Double" 'Double
		case adCurrency:typ = "Money" 'Currency
		case adDecimal:typ = "Decimal"
		case adNumeric:typ = "Numeric" 'Numeric
		case adBoolean:typ = "Bit" 'Boolean
		case adError:typ = "Error"
		case adUserDefined:typ = "UserDefined"
		case adVariant:typ = "Variant"
		case adIDispatch:typ = "IDispatch"
		case adIUnknown:typ = "IUnknown"
		case adGUID:typ = "GUID" 'GUID
		case adDATE:typ = "DateTime" 'Date
		case adDBDate:typ = "DBDate"
		case adDBTime:typ = "DBTime"
		case adDBTimeStamp:typ = "DateTime" 'DBTimeStamp
		case adBSTR:typ = "BSTR"
		case adChar:typ = "Char"
		case adVarChar:typ = "VarChar"
		case adLongVarChar:typ = "LongVarChar"
		case adWChar:typ = "Text" 'WChar类型 SQL中为Text
		case adVarWChar:typ = "VarChar" 'VarWChar
		case adLongVarWChar:typ = "Text" 'LongVarWChar
		case adBinary:typ = "Binary"
		case adVarBinary:typ = "VarBinary"
		case adLongVarBinary:typ = "LongBinary"'LongVarBinary
		case adChapter:typ = "Chapter"
		case adPropVariant:typ = "PropVariant"
		case else:typ = "Unknown"
	end select
End Function

%>
    <%
'==================================================================返回字段类型列表
Function fieldtypelist(n)
	dim strlist,str1,str2
%>
        <%
	strlist = "<select name=""field_type"" lay-verify="""">"
	if session("dbtype") = "access" then
		strlist = strlist & "<option value=""VarChar"">文本</option>"
		strlist = strlist & "<option value=""Bit"">(是/否)</option>"
		strlist = strlist & "<option value=""Integer"">数字(长整型)</option>"
		strlist = strlist & "<option value=""Single"">数字(单精度)</option>"
		strlist = strlist & "<option value=""Double"">数字(双精度)</option>"
		strlist = strlist & "<option value=""Numeric"">数字(小数)</option>"
		strlist = strlist & "<option value=""GUID"">数字(同步ID)</option>"
		strlist = strlist & "<option value=""DateTime"">时间/日期</option>"
		strlist = strlist & "<option value=""Money"">货币</option>"
		strlist = strlist & "<option value=""Text"">备注</option>"
	else
		strlist = strlist & "<option value="""">选择类型</option>"
		strlist = strlist & "<option value=""BigInt"">bigint</option>"
		strlist = strlist & "<option value=""Binary"">binary(二进制数据类型)</option>"
		strlist = strlist & "<option value=""Bit"">bit(整型)</option>"
		strlist = strlist & "<option value=""Char"">char(字符型)</option>"
		strlist = strlist & "<option value=""DateTime"">datetime(日期时间型)</option>"
		strlist = strlist & "<option value=""Decimal"">decimal(精确数值型)</option>"
		strlist = strlist & "<option value=""Float"">float(近似数值型)</option>"
		strlist = strlist & "<option value=""Image"">image(二进制数据类型)</option>"
		strlist = strlist & "<option value=""Int"">int(整型)</option>"
		strlist = strlist & "<option value=""Money"">money(货币型)</option>"
		strlist = strlist & "<option value=""nchar"">nchar(统一编码字符型)</option>"
		strlist = strlist & "<option value=""ntext"">ntext(统一编码字符型)</option>"
		strlist = strlist & "<option value=""numeric"">numeric(精确数值型)</option>"
		strlist = strlist & "<option value=""nvarchar"">nvarchar(统一编码字符型)</option>"
		strlist = strlist & "<option value=""real"">real(近似数值型)</option>"
		strlist = strlist & "<option value=""smalldatetime"">Smalldatetime(日期时间型)</option>"
		strlist = strlist & "<option value=""smallint"">smallint(整型)</option>"
		strlist = strlist & "<option value=""smallmoney"">smallmoney(货币型)</option>"
		strlist = strlist & "<option value=""sql_variant"">sql_variant()</option>"
		strlist = strlist & "<option value=""text"">text(字符型)</option>"
		strlist = strlist & "<option value=""timestamp"">timestamp(特殊数据型)</option>"
		strlist = strlist & "<option value=""tinyint"">tinyint(整型)</option>"
		strlist = strlist & "<option value=""uniqueidentifier"">Uniqueidentifier(特殊数据型)</option>"
		strlist = strlist & "<option value=""varbinary"">varbinary(二进制数据类型)</option>"
		strlist = strlist & "<option value=""varchar"">varchar(字符型)</option>"
	end if
	str1 = """" & n & """"
	str2 = """" & n & """" & " selected"
	strlist = replace(strlist,str1,str2)
	strlist = strlist & "</select>"
	echo strlist
End Function
%>

            <%
'==================================================================创建表界面
sub add_table(table_name,field_num)
	on error resume next
	if not IsNumeric(field_num) then
		echo "字段数必须是整数。"
		echo "<input type='button' name='ok' value=' 返 回 ' onClick='javascript:history.go(-1)'>"
		exit sub
	end if
	%>
                <p class="hei"><span>创建表：</span>
                    <%=table_name%>
                </p>
                <form action="?key=createtable" method="post">
                    <table width="600" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC" class="layui-table">
                        <tr>
                            <td width="75" height="20" align="center">字段名</td>
                            <td width="99" height="20" align="center">类 型</td>
                            <td width="73" height="20" align="center">大 小</td>
                            <td width="96" height="20" align="center">空值</td>
                            <td width="83" height="20" align="center">自动编号</td>
                            <td width="143" height="20" align="center">主 键</td>
                        </tr>
                        <% dim i
	 for i = 0 to field_num - 1 %>
                            <tr>
                                <td width="75" height="20" align="center">
                                    <input type="text" name="field_name" size="10">
                                </td>
                                <td width="99" height="20" align="center">
                                    <% fieldtypelist(0) %>
                                </td>
                                <td width="73" height="20" align="center">
                                    <input type="text" name="field_size" size="10">
                                </td>
                                <td width="96" height="20" align="center">
                                    <select name="null">
              <option value="NOT_NULL">NOT_NULL</option>
              <option value="NULL">NULL</option>
            </select>
                                </td>
                                <td width="83" height="20" align="center">
                                    <select size="1" name="autoincrement">
            <option></option>
            <option>自动编号</option>
          </select>
                                </td>
                                <td width="143" height="20" align="left">
                                    <select name="primarykey">
                <option></option>
                <option value="primarykey">primarykey</option>
              </select>
                                </td>
                            </tr>
                            <% next %>
                                <tr>
                                    <td height="35" align="center" colspan="5">
                                        <input type="hidden" name="i" value=<%=field_num%>>
                                        <input type="hidden" name="table_name" value="<%=table_name%>">
                                        <input type="submit" name="Submit" value=" 提 交 " class="layui-btn"> &nbsp;&nbsp;
                                        <input type="reset" name="Submit2" value=" 重 置 " class="layui-btn"> &nbsp;&nbsp;
                                        <input type="button" name="ok" value=" 放 弃 " onClick="javascript:history.go(-1)" class="layui-btn">
                                    </td>
                                    <td height="20"></td>
                                </tr>
                    </table>
                </form>
                <%
end sub

'==================================================================构建创建表的SQL语句
sub create_table()
	dim sql,i,primarykey
	on error resume next
	sql = "CREATE TABLE ["&request("table_name")&"] ("
	for i = 1 to request("i")
	   sql = sql & "[" & request("field_name")(i) & "] " & request("field_type")(i)
		  if request("field_size")(i) <> "" then
			  sql = sql & "(" & request("field_size")(i) & ")"
		  end if
		  if request("null")(i) = "NOT_NULL" then
			  sql = sql & " not null"
		  end if
		  if request("autoincrement")(i) = "自动编号" then
			  sql = sql & " identity"
		  end if
		  if request("primarykey")(i) = "primarykey" then
			  primarykey = request("field_name")(i)
		  end if
 	   sql = sql & ","
		  
		' if primarykey <> "" then
		   ' sql = sql & ","
		' end if
	next
	if primarykey<>"" then
	   sql=sql&" primary key (["&primarykey&"]) "
	else
		sql=left(sql,len(sql)-1)
	end if
	sql = sql & ")"
	sql = replace(sql,"()","")  '构建空表
	response.redirect "?key=sql&sql=" & sql 
end sub

'==================================================================主界面
sub main(str)
	on error resume next
%>
                    <script language=javascript>
                        ie = (document.all) ? true : false
                        if (ie) {
                            function ctlent(eventobject) {
                                if (event.ctrlKey &&
                                    window.event.keyCode == 13) {
                                    this.document.exesql.submit();
                                }
                            }
                        }
                    </script>
                    <script language="javascript">
                        function table_delete() {
                            if (confirm("确认删除该记录吗？   该操作将不可撤销！！！"))
                                return true;
                            else
                                return false;
                        }
                    </script>
                    <% if val("str")="" then %>
                        <div style="display:<%if val(" str ")=" " then echo "none " %>">
                            <%else%>
                                <div>
                                    <%end if%>
                                        <div class="layui-fluid">
                                            <div class="layui-card">
                                                <div class="layui-card-body">
                                                    <form action="?key=sql" method=post name="exesql">
                                                        <font color=red>执行sql语句：</font>
                                                        <font color=#999999>(每句语句以“;”结束，支持(--)SQL注释，Ctrl + Enter 快速提交)</font>&nbsp; <input type="button" class="layui-btn" value="刷新本页" onClick="javascript:location.reload()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                        <span onClick="document.exesql.sql.rows+=5;" style="cursor:pointer;">+</span>
                                                        <span onClick="if(document.exesql.sql.rows>9)document.exesql.sql.rows-=5" style="cursor:pointer;">-</span>
                                                        <div style="float:left;width:600px;">
                                                            <textarea id="sql" name="sql" style="width:600px;" rows="9" ondblClick="this.select();" onKeyDown="ctlent()"><%=request("sql")%></textarea><br />
                                                            <input type="checkbox" name="SchemaTable" value="1" style="border:0px;">adSchemaTables
                                                            <input type="checkbox" name="SchemaColumn" value="2" style="border:0px;">adSchemaColumns
                                                            <input type="checkbox" name="SchemaProvider" value="3" style="border:0px;">adSchemaProviderTypes &nbsp; 分页大小：
                                                            <select name="pageSize">
		  <%
		  if request("pageSize") <> "" and  isNumeric(request("pageSize")) then
		     echo "<option value='"&request("pageSize")&"' selected>"&request("pageSize")&"</option>"
		  else
		     echo "<option value='50'>50</option>"
		  end if
		  %>
		  <option value="10">10</option>
		  <option value="20">20</option>
		  <option value="30">30</option>
		  <option value="40">40</option>
		  <option value="50">50</option>
		  <option value="60">60</option>
		  <option value="70">70</option>
		  <option value="80">80</option>
		  <option value="90">90</option>
		  <option value="100">100</option>
		</select>
                                                        </div>
                                                        <div style="float:left;width:50px;padding:60px 0px 0px 5px;">
                                                            <input type="submit" name="Submit_confirm" value="提交" class="layui-btn"> <br /> <br />
                                                            <input type="button" name="Submit3" value="清空" onClick="sql.value=''" class="layui-btn"><br /><br />
                                                            <input type="button" name="ok" value="返回" onClick="javascript:history.go(-1)" class="layui-btn">
                                                        </div>
                                                    </form>
                                                    <div style="clear:both"></div>
                                                    <% if str = "" then %>
                                                        <form action="?key=addtable" method="post">
                                                            <br />
                                                            <font color=red>创建新表：</font><br>
                                                            <div class="layui-inline">
                                                                <label class="layui-form-label">表&nbsp;&nbsp;名：</label>
                                                                <div class="layui-input-inline">
                                                                    <input type="text" name="table_name" size="20" class="layui-input">
                                                                </div><br><br>
                                                                <label class="layui-form-label">字段数：</label>
                                                                <div class="layui-input-inline"><input type="text" name="field_num" size="20" class="layui-input"></div>
                                                            </div>
                                                            <br>
                                                            <br>
                                                            <div class="layui-form-item">
                                                                <input type="submit" name="Submit_create" value="提交" class="layui-btn">
                                                                <input type="reset" name="Submit32" value="重置" class="layui-btn">
                                                            </div>

                                                        </form>
                                                        <br><br>
                                                        <a href="?key=tosql&strt=2">导出所有表结构到SQL</a>
                                                        <%
	end if
	%>
                                                </div>
                                            </div>
                                        </div>
                                </div>
                                <%
end sub
'==================================================================修改表名或字段名 2006-09-08
sub reobj()
	on error resume next
	Dim mydb,mytable,tablename
	tablename = request("tablename")
	Set mydb = Server.CreateObject("ADOX.Catalog")
	mydb.ActiveConnection = conn
		
	if request("obj") = "field" then   '修改字段名
		dim fieldsname,newfieldsname
		fieldsname = request("fieldsname")
		newfieldsname = request("newfieldsname")
		Set mytable = Server.CreateObject("ADOX.Table")
		Set mytable = mydb.Tables(tablename) 
		mytable.Columns(fieldsname).Name = newfieldsname
	end if
	
	if request("obj") = "table" then   '修改表名
		dim newtablename
		newtablename = request("newtablename")
		mydb.Tables(tablename).Name = newtablename
	end if
	
	if err <> 0 then
		echo  err.description
		echo "<input type='button' name='ok' value=' 返 回 ' onClick='javascript:history.go(-1)'>"
		exit sub
	end if
	
	if request("obj") = "field" then
		response.Redirect "?key=view&table_name=" & tablename
	else
		response.Redirect "?key=view&table_name=" & newtablename
	end if
	
end sub

'==================================================================修改字段属性的界面
sub editfidlevi()
	dim sql,rs,i
	on error resume next
	sql = "Select * From [" & request("table_name") & "]"
	set rs = conn.execute(sql)
	for i = 0 to rs.fields.count - 1
		if rs(i).name = request("fidle") then
		%>
                                    <script LANGUAGE="JavaScript">
                                        function validate(theForm) {
                                            if (theForm.type.value == "") {
                                                alert("请输入数据类型");
                                                theForm.type.focus();
                                                return (false);
                                            }
                                            return (true);
                                        }
                                    </script>
                                    <font color=red>修改字段属性：</font>
                                    <form action="?key=editfidle&fidle=<%=request(" fidle ")%>&table_name=<%=request("table_name ")%>" method="post" name=frm onSubmit="return validate(frm)">
                                        <table width="600" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC" class="layui-table">
                                            <tr>
                                                <td width="60" height="20" align="center">字段名</td>
                                                <td width="50" height="20" align="center">类型</td>
                                                <td width="58" height="20" align="center">设定大小</td>
                                                <td width="64" height="20" align="center">允许空值</td>
                                                <td width="66" height="20" align="center">自动编号</td>
                                                <td width="96" height="20"></td>
                                            </tr>
                                            <tr>
                                                <td width="60" height="20" align="center">
                                                    <%=rs(i).name%>
                                                </td>
                                                <td width="50" height="20" align="center">
                                                    <% fieldtypelist(request("fidletype")) %>
                                                </td>
                                                <td width="58" height="20"><input type="text" name="size" size="10"></td>
                                                <td width="64" height="20" align="center">
                                                    <input type="checkbox" name="null" value="null" <%=iif((rs(i).Attributes and adFldIsNullable)=0, "", " checked")%>>
                                                </td>
                                                <td width="66" height="20" align="center">
                                                    <input type="checkbox" name="autoincrement" value="y" <%=iif(rs(i).Properties( "ISAUTOINCREMENT")=True, " checked", "")%>>
                                                </td>
                                                <td width="96" height="20" align="center">
                                                    <input type="submit" name="Submit" value="提交" class="layui-btn">
                                                </td>
                                            </tr>
                                        </table><br>
                                    </form>
                                    <%
		end if
	next
end sub

'==================================================================执行修改字段属性
sub editfidle()
	   on error resume next
	   dim sql
	   sql = "ALTER TABLE [" & request("table_name") & "] "
	   sql = sql&"ALTER COLUMN [" & request("fidle") & "] "
	   if request("field_type") <> "" then
		  sql = sql & request("field_type")
	   end if
	   if request("size") <> "" then
		  sql = sql & "(" & request("size") & ") "
	   end if
		  if request("null") = "" then
			  sql = sql & " not null"
		  end if
		  if request("autoincrement") = "y" then
			  sql = sql & " identity"
		  end if
	sql = trim(sql)
	conn.execute(sql)
	' echo sql
	response.redirect "?key=view&table_name="& request("table_name")
end sub

'==================================================================添加字段函数
sub addfield()
	on error resume next
	dim fldname,fldtype,fldsize,fldnull,table_name,fldautoincrement,sql
	fldname = request("fldname")
	fldtype = request("field_type")
	fldsize = request("fldsize")
	fldnull = request("null")
	fldautoincrement = request("autoincrement")
	table_name = request("table_name")
	if fldname <> "" and fldtype <> "" then
	  sql = "alter table [" & table_name & "] add ["&fldname&"] " & fldtype
	  
	  if fldsize <> "" then
		sql = sql & "(" & fldsize & ")"
	  end if 
	  
	  if fldnull = "ON" then
	  end if
	  if isnull(fldnull) then
		sql = sql & " not null"
	  end if
	  
	  if fldautoincrement = "ON" then
		sql = sql & " identity"
	  end if
	  conn.execute(sql)
	if err <> 0 then
		echo err.description
		echo "<input type='button' name='ok' value=' 返 回 ' onClick='javascript:history.go(-1)'>"
		response.end
	end if
	
	  dim sqla(5),ret
	  easp.var("f1")=easp.var("canValue") 
	  easp.var("dbName") = session("dbName")
	  sqla(0) = cr("baseinfo3","f1,dbName,fldname,table_name")
	  ret=execsw(sqla)
	  
	  sqla(0) = xg("baseinfo3","f1","dbName=" & da(easp.var("dbName")) &" and fldname=" & da(easp.var("fldname")) & " and table_name=" & da(easp.var("table_name")))
	  ret=execsw(sqla)
	  ' echo sql
	  response.redirect "?key=view&table_name=" & table_name 
	else
	  echo "输入数据错误！<input type='button' name='ok' value=' 返 回 ' onClick='javascript:history.go(-1)'>"
	end if
end sub

function newid(tn)
	dim rs,sql
	Set rs = server.CreateObject("adodb.recordset")
	sql = "select * from "&tn
	rs.open sql,conn,3,2
	rs.addnew
	rs("numb")="0"  
	rs.update
	rs.movelast
	newid = rs("id")
	rs("numb")="00"&newid
	rs.update
	rs.Close
	Set rs = Nothing
	' conci()		
end function
function henji(numb)
	dim sql
	vas "numb",numb
	vas "f1",session("username")
	vas "mode","inputlog"
	Easp.Db.Del "baseinfo3","dbName={dbName} and table_name={table_name} and numb={numb} and mode={mode}"
	sql = cr("baseinfo3","dbName,table_name,numb,f1,mode")
	Easp.Db.Exec(sql)
end function


sub editdata2()
	dim keys,names,values,action,rs,sql,tab
	' on error resume next
	keys = request("primarykey")
	names = request("table_name")
	values = request("primarykeyvalue")
	action = request("action")
	Set rs = Server.CreateObject("Adodb.RecordSet")

	dim myfields,txt,rs_bi0,ii,cnt	
	ii=0
	Set rs_bi0 = Easp.Db.Sel("select fld,mm1 from bi0 where tn={table_name} and dbName={dbName} order by id")
	cnt=rs_bi0.recordCount
	Dim myArray(),mymm()
	reDim myArray(cnt+1),mymm(cnt+1)
	myArray(ii)="ID"
	mymm(ii)="自动编号"
	ii=1
	Do While Not rs_bi0.EOF		
		txt=txt&rs_bi0("fld")&","
		myArray(ii)=rs_bi0("fld")
		mymm(ii)=rs_bi0("mm1")
		rs_bi0.MoveNext
		ii=ii+1
	Loop		

	dim sql_max,myid,maxid,hnext
	
	sql_max="select max(id) as id from "&names
	maxid=cstr(Easp.Db.Select(conn2,sql_max)("id"))

	if action = "" or action = "save" or action = "new" then
		sql = "select * from " & names & " where " & keys & " = " & values
	end if
	
	
	if action = "pre" then
	    sql = "select top 1 * from " & names & " where " & keys & " < " & values & " order by " & keys & " desc"
	end if
	dim url
	if action = "next" then
	    sql = "select top 1 * from " & names & " where " & keys & " > " & values & " order by " & keys & " asc"
		rs.Open sql, conn, 1, 3
		if rs.recordCount=0 then
			myid = newid(names)
			sql = "select * from " & names & " where " & keys & " = " & myid
			url="http://epi.yjk99.in/dzps/ct1.asp?key=edit&table_name="& names &"&primarykey=ID&primarykeyvalue="&myid
			Response.Redirect(url)			
		end if
		if cstr(rs("id"))=maxid then 
			hnext=true
		end if
		if values="1" then values="2" end if
	end if

	if action = "add" then
		myid = newid(names)
	    sql = "select * from " & names & " where " & keys & " = " & myid
		url="http://epi.yjk99.in/dzps/ct1.asp?key=edit&table_name="& names &"&primarykey=ID&primarykeyvalue="&myid
		Response.Redirect(url)			
	end if

	if action <>"next" then
		rs.Open sql, conn, 1, 3
	end if
	if rs.eof and action = "new" then
		sql = "Select * From [" & names & "]"
		rs.Open sql, conn, 1, 3
	end if
	
	if action = "save" or action = "new" then
		If action = "new" Then rs.AddNew
		For Each tab In rs.Fields
			If Keys <> tab.Name and tab.Name <> "NUMB" Then
				rs(tab.Name) = Request.Form(tab.Name & "_Column")
				if err <> 0 then
					echo tab.name & err.description
					echo "<input type='button' name='ok' value=' 返 回 ' onClick='javascript:history.go(-1)' class='layui-btn'>"
					response.end
				end if
			End If
		Next
		rs.update
		' conci()
		henji(Request.Form("NUMB_Column"))
	end if
	
	echo "字段数据编辑<br>"
	echo "<table width=600 border=0 cellpadding=5 cellspacing=1 bgcolor=#CCCCCC class='layui-table'><tr><td>"
	echo "<form action='?key=edit&table_name=" & names & "&primarykey=" & keys & "&primarykeyvalue=" & rs(keys) & "' method='post' name='editor'>"
	echo "<br>"
	
	echo "<input type=hidden name=action value=save>"
	' echo iif(action="add","","<input type=submit value=保存 onclick=this.form.action.value='save'; class='layui-btn'>&nbsp;")
	echo "<input type=submit value=保存 onclick=this.form.action.value='save'; class='layui-btn'>&nbsp;"
	' echo "<input type=button class='layui-btn' value=添加 onclick=if(confirm('确实要添加当前为新记录吗?')){this.form.action.value='new';this.form.submit();};>&nbsp;"
	echo iif(values="1","", "<input type=button class='layui-btn' value=上一例 onclick=""this.form.action.value='pre';this.form.submit();"">&nbsp;")
	echo iif(hnext or values=maxid,"","<input type=button class='layui-btn' value=下一例 onclick=""this.form.action.value='next';this.form.submit();"">&nbsp;&nbsp;")
	echo "<a href='?key=sql&sql=select * from " & names & " order by id&table_name="& names & "&primarykey="&keys&"'"& "class='layui-btn'" &  ">表浏览</a>&nbsp;&nbsp;"
	if not rs.eof or action = "add" then
		For ii=0 to UBound(myArray)
			myArray(ii)=trim(myArray(ii))
			if right(val("table_name"),1)<>"1" and ii=0 then
				echo "<br>"				
				echo "<BR><font color=red>" & "NUMB" & "</font>&nbsp;<font color=#999999>( "  & "编号"  & " )</font>" '
				echo "<div class='layui-input-inline'>" 
				echo "<input type='text' name='" & "NUMB_Column'" & " " 'style='width:600;'
				echo IIf("NUMB" = "NUMB" , " disabled title='NUMB主键约束,将无法被修改.'", " ") & " value='"
				if action <> "add" then echo rs("NUMB") end if
				echo "' class='layui-input' lay-verify='number'  >"
				echo "</div>"				
				echo "<br>"				
			end if
			if myArray(ii)<>"" then
				if InStr(myArray(ii),"blank")=0 then	
					if myArray(ii)<>"ID" and InStr(myArray(ii),"blank")=0  then 'trim(myArray(ii))<>"ID" and and instr(mymm(ii),"(") =0
						echo "<BR><font color=red>" & myArray(ii) & "</font>&nbsp;<font color=#999999>( "  & session("mydict").item(myArray(ii))   &  " )</font>" '<br>
						echo "<div class='layui-input-inline'>" 
						echo "<input type='text' name='" & myArray(ii) & "_Column'" & " " 'style='width:600;'
						echo IIf(myArray(ii) = "NUMB", " disabled title='NUMB主键约束,将无法被修改.'", " ") & " value='"
						if action <> "add" then echo rs(myArray(ii)) end if
						echo "' class='layui-input' lay-verify='number'>"
						echo "</div>"
						echo mymm(ii)
						echo "<br>"				
					elseif myArray(ii)="ID" then
						' echo "<BR><font color=red>" & myArray(ii) & "</font>&nbsp;<font color=#999999>( "  & "自动编号"  & " )</font><br>" '
						' echo "<div class='layui-input-inline'>" 
						' echo "<input type='text' name='" & myArray(ii) & "_Column'" & " " 'style='width:600;'
						' echo IIf(myArray(ii) = keys, " disabled title='主键约束,将无法被修改.'", " ") & " value='"
						' echo rs(myArray(ii))
						' echo "' class='layui-input' lay-verify='number' >"
						' echo "</div>"
						' ' echo mymm(ii)
						' echo "<br>"	
					elseif instr(mymm(ii),"(") >0  then 'and 0<>0 '
						echo "<BR><font color=red>" & myArray(ii) & "</font>&nbsp;<font color=#999999>( "  & session("mydict").item(myArray(ii))   &  " )</font>" '<br>
						echo "<div class='layui-input-inline'>" 
						echo "<input type='text' name='" & myArray(ii) & "_Column'" & " " 'style='width:600;'
						echo IIf(myArray(ii) = keys, " disabled title='主键约束,将无法被修改.'", " ") & " value='"
						if action <> "add" then echo rs(myArray(ii)) end if
						echo "' class='layui-input' lay-verify='number'>"
						echo "</div>"
						echo "--" & mymm(ii)
						echo "<br>"	

					end if
				else
					echo "<font color=red>"  & "</font>&nbsp;<font color=blue> "  & mymm(ii)  & " </font>" '
					echo "<br>"				
				end if
			end if
		next
		
	' else
		' echo "<script>alert('已经没有了!');history.back();</script>"
		' Response.End()
	end if
	echo "<br>"
	' echo iif(action="add","","<input type=submit value=保存 onclick=this.form.action.value='save'; class='layui-btn'>&nbsp;")
	echo "<input type=submit value=保存 onclick=this.form.action.value='save'; class='layui-btn'>&nbsp;"
	' echo "<input type=button class='layui-btn' value=添加 onclick=if(confirm('确实要添加当前为新记录吗?')){this.form.action.value='new';this.form.submit();};>&nbsp;"
	' echo "<input type=button class='layui-btn' value=上一例 onclick=""this.form.action.value='pre';this.form.submit();"">&nbsp;"
	echo iif(values="1","", "<input type=button class='layui-btn' value=上一例 onclick=""this.form.action.value='pre';this.form.submit();"">&nbsp;")
	echo iif(hnext or values=maxid,"","<input type=button class='layui-btn' value=下一例 onclick=""this.form.action.value='next';this.form.submit();"">&nbsp;&nbsp;")
	echo "<a href='?key=sql&sql=select * from " & names & " order by id&table_name="& names & "&primarykey="&keys&"'"& "class='layui-btn'" &  ">表浏览</a>&nbsp;&nbsp;"
	echo "</form></td></tr></table>"
end sub

function bl_0()
	dim rs,arr,maxcol,maxrow,i,j
	set rs = Easp.Db.Sel("select top 15 fld,colName,mm1,regu1,tn from bi0 where dbName='追风透骨胶囊治疗骨关节炎数据库'  order by id")
	if rs.recordCount >=1 then
		arr = rs.GetRows
	end if
	maxcol=ubound(arr,1)
	maxrow=ubound(arr,2)
	for i=0 to maxrow
		for j=0 to maxcol
			' echo arr(j,i)
		next
		' echo "<br>"
	next
end function
function myopt(fld,colName,arr,id1)
	myopt=myopt2(fld,colName,arr,id1)
	myopt="<div class='layui-form-item'>"& myopt &"</div>"
end function
function myopt2(fld,colName,arr,id1)
	dim txt,i,arr0,head,opt
	for i=0 to ubound(arr,2)
		if arr(0,i)=cint(id1) then
			opt="<option value='[value]' selected data-filtered='filtered'>[title]</option>"
			txt=txt&replace(replace(opt,"[value]",arr(0,i)),"[title]",arr(1,i))
		else
			opt=replace("<option value='[value]' selected data-filtered='filtered'>[title]</option>","selected","") 
			txt=txt&replace(replace(opt,"[value]",arr(0,i)),"[title]",arr(1,i))
		end if
	next
	head=replace("<label class='layui-form-label'>[dy:label]</label><div class='layui-input-inline'><select id='sel_[dy:name]' name='[dy:name]' lay-filter='[dy:name]' lay-verify='required' data-filtered='filtered' readonly='' class='layui-input'>","[dy:name]",fld)
	head=replace(head,"[dy:label]",colName)
	myopt2=head &  "<option value=''>请选择["& colName &"]</option>" &txt &"</select></div>"
end function
function myopt3_1(fld,colName,arr,id1)
	myopt3_1=myopt3(fld,colName,arr,id1)
	myopt3_1="<div class='layui-form-item'>"& myopt3_1 &"</div>"
end function
function myopt3(fld,colName,arr,id1)
	dim txt,i,arr0,head,opt
	for i=0 to ubound(arr,2)
		opt="<option value='[value]' selected data-filtered='filtered'>[title]</option>"
		if arr(0,i)<>id1 then
			opt=replace(opt,"selected","") 
		end if
		txt=txt&replace(replace(opt,"[value]",arr(0,i)),"[title]",arr(1,i))
	next
	head=replace("<label class='layui-form-label'>[dy:label]</label><div class='layui-input-inline'><select id='sel_[dy:name]' name='[dy:name]' lay-filter='[dy:name]' lay-verify='required' data-filtered='filtered' readonly='' class='layui-input'>","[dy:name]",fld)
	head=replace(head,"[dy:label]",colName)
	myopt3=head &  "<option value=''>请选择["& colName &"]</option>" &txt &"</select></div>"
end function
function selnolable(opt,colName)
'删除label 和 layui-input-inline'
	selnolable= replace("<label class='layui-form-label'>[dy:label]</label><div class='layui-input-inline'>","[dy:label]",colName) 
	selnolable= replace(opt,selnolable,"")
	selnolable=left(selnolable,len(selnolable)-6) '删除</div>'
end function
function myopt2_no_required(fld,colName,arr,id1)
	myopt2_no_required=replace(myopt2(fld,colName,arr,id1),"lay-verify='required'","")
end function
function myopt3_no_required(fld,colName,arr,id1)
	myopt3_no_required=replace(myopt3(fld,colName,arr,id1),"lay-verify='required'","")
end function
function mymm2(fld,colName,mm1,id1)
	dim arr,txt,i,txt2,arr0,head,txt3
	mm1=trim(mm1)
	mm1=replace(mm1,"(","")
	mm1=replace(mm1,")","")
	mm1=replace(mm1,"'","")
	
	arr=split(mm1,"，")
	txt2="<option value='[value]' data-filtered='filtered'>[title]</option>"
	txt3="<option value='[value]' selected data-filtered='filtered'>[title]</option>"
	for i=0 to ubound(arr)
		arr0=split(arr(i),"-")
		if (ubound(arr0)=1) then
			if (id1=arr0(0)) then
				txt=txt&replace(replace(txt3,"[value]",arr0(0)),"[title]",arr0(1))
			else
				txt=txt&replace(replace(txt2,"[value]",arr0(0)),"[title]",arr0(1))
			end if
		else
			txt=txt&replace(replace(txt2,"[value]",arr(i)),"[title]",arr(i))
		end if
	next
	head=replace("<label class='layui-form-label'>[dy:label]</label><div class='layui-input-block'><select name='[dy:name]' lay-verify='required' data-filtered='filtered' readonly='' class='layui-input'>","[dy:name]",fld)
	head=replace(head,"[dy:label]",colName)
	mymm2=head&txt&"</select></div>"
end function

sub showproc()
	dim sTableName,adox
	on error resume next
	echo "存储过程：<font color=red>" & Request("table_name") & "<font><br>"
	sTableName = Request("table_name")
	Set adox = Server.CreateObject("ADOX.Catalog")
	adox.ActiveConnection = Conn
	echo "<textarea cols=70 rows=8>" & adox.Procedures(sTableName).Command.CommandText & "</textarea><br>"
	if err <> 0 then
		echo err.description
		exit sub
	end if
end sub

sub showNavBar (rs,page,pageUrl,pageSize)
	page = cint(page)
	%>
                                        <br>
                                        <table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">
                                            <tr>
                                                <% if request("primarykey") <> "" and request("table_name") <> "" then %>
                                                    <td align="left">当前表：
                                                        <font color=red>
                                                            <%=request("table_name")%>
                                                        </font>&nbsp;&nbsp;&nbsp;&nbsp;
                                                        <%if right(val("table_name"),1)="1" then %>
                                                            <!--<a href="?key=edit&table_name=<%=request("table_name")%>&primarykey=<%=request("primarykey")%>&action=add">插入新记录</a>-->
                                                            <button id="demo1" class="layui-btn" lay-filter="demo1">插入新记录</button>
                                                            <%end if%>
                                                    </td>
                                                    <% end if %>
                                                        <td align="right">
                                                            <%
		' echo "共有" & rs.recordCount & "条记录 当前" & page & "/" & rs.PageCount & "页"
	    if page > 1 then
			echo "<a href='" & pageUrl & "&page=1&pageSize="&pageSize&"'>首页</a> " 
			echo "<a href='" & pageUrl & "&page=" & page - 1 & "&pageSize="&pageSize&"'>上页</a> "
	    end if
		if (rs.PageCount > 1 and page < rs.PageCount) then
			echo "<a href='" & pageUrl & "&page=" & page + 1 & "&pageSize="&pageSize&"'>下页</a> "
			echo "<a href='" & pageUrl & "&page=" & rs.pageCount & "&pageSize="&pageSize&"'>末页</a> "
		end if
		' echo "转到:第"
		echo "<select name='select2' onChange='location.href=this.value;'>"
		dim i
		for i = 1 to rs.PageCount
			echo "<option value='"& pageUrl &"&pageSize="&pageSize&"&page="& i & "' "
			if i = cint(page) then echo "selected"
			echo ">"& i &"</option>"
		next
		echo "</select>Page"
	    %>
                                                        </td>
                                            </tr>
                                        </table>
                                        <%
end sub

sub showselect(sql)
	dim page,pageUrl,strdel,geturl,pageSize,numb
	pageSize = request("pageSize") 			'设置每页显示的记录数
	if pageSize = "" or not isNumeric(pageSize) then pageSize = 50

	'判断是否删除
	if request("keylog") <> "" then
			
		numb = conn.execute("select numb from " & val("table_name") & " where id=" & request("keylog"))("numb")
		strdel = "delete from " & request("table_name") & " where " & request("primarykey") & "=" & request("keylog")
		response.Write strdel
		conn.execute(strdel)
		conci_del(numb)
		
		
		geturl = "?" & replace(request.QueryString,"&keylog="&request("keylog"),"")
		response.Redirect geturl
	end if
	
	page = request("page")           '设置当前显示的页数
	if page="" or not isNumeric(page) then page=1
	pageUrl = "?key=sql&sql=" & sql
	if request("primarykey") <> "" and request("table_name") <> "" then
	  pageUrl = pageUrl & "&table_name=" & request("table_name") & "&primarykey=" & request("primarykey")
	end if
	
	'--------------------------
   dim rs
   set rs = Server.CreateObject("ADODB.Recordset")
	dim w
	w=inputman()
	if w<>"" then
		w=" numb in (" & w &  ") "
		if session("username")<>"admin" then
			sql=replace(sql,"1=1",w)
		end if
	end if
   ' echo sql
   
   rs.Open sql,conn,3
   
   if not rs.eof then
   	  rs.pageSize = pageSize
	  if cint(page) < 1 then page = 1
   	  if cint(page) > rs.PageCount then page = rs.PageCount
   	  rs.absolutePage = page
   end if
	
	'显示分页导航
   showNavBar rs,page,pageUrl,pageSize
   
   '-------------------------------
   echo "<div style='overflow-x:auto;overflow-y:auto; width:800;height:380;'>"
   echo "<table border=0 border=0 cellpadding=3 cellspacing=1 bgcolor=#CCCCCC class=""layui-table""><tr>"
   dim primarykey
   primarykey = request("primarykey")
   if primarykey <> "" and request("table_name") <> "" then
   echo "<td bgcolor=#ffffff>操作</td><td bgcolor=#ffffff>删</td>"
   end if
      fcnt=rs.fields.count
	  if fcnt >=8 then
		fcnt=8
	  end if
   for i = 0 to rs.fields.count - 1         '循环字段名
		set field = rs.fields.item(i)
		echo "<td bgcolor=#ffffff>" & field.name & " </td>"
	

   next
   echo "</tr>"
   
   dim i,field,j,fcnt
   dim myid,mynumb
   do while not rs.eof and j < rs.pageSize                    '循环数据
      echo "<tr>"
	  
	  if primarykey <> "" and request("table_name") <> "" then
	  echo "<td bgcolor=#ffffff nowrap><a href='?key=edit&table_name=" & request("table_name") & "&primarykey=" & primarykey & "&primarykeyvalue=" & rs(primarykey) & "'><font color=#666666>编辑</font></a></td>"
	  echo "<td><a href='?"&Request.QueryString&"&keylog="&rs(primarykey)&"' onClick='return table_delete();'><font color=#FF000>×</font></a></td>"
	  end if
		
	  for i = 0 to rs.fields.count - 1
         set field = rs.fields.item(i)
		 if len(field.value) < 12 then
			echo "<td bgcolor=#ffffff nowrap>" & field.value & " </td>"

		 else
		 	echo "<td bgcolor='#ffffff'><span class='fixspan'>" & field.value & " </span></td>"
		 end if
      next
      echo "</tr>"
      rs.MoveNext
      j = j + 1
   loop
   'response.ContentType ="application/vnd.ms-excel"'生成EXCEL表格
   echo "</table></div>"
   
end sub


sub exesql(sql)
    if trim(request.form("SchemaTable")) <> "" then Call showSchema (adSchemaTables)
    if trim (request.form("SchemaColumn")) <> "" then Call showSchema(adSchemaColumns)
    if trim (request.form("SchemaProvider")) <> "" then Call showSchema(adSchemaProviderTypes)
	' dim err
	sql = trim(request("sql"))
	if sql = "" then exit sub
	
    sql = RegExpReplace(sql, "(--)(.)*\n", "")   '替换注释
    sql = RegExpReplace(sql, "\n[\s| ]*\r", "")  '替换空行
    sql = RegExpReplace(sql, "\n", "")           '替换换行符
    sql = RegExpReplace(sql, "\r", "")           '替换回车符
    if (LCase(left(sql,len("select"))) = "select") and instr(sql,"into") = 0 then
	   Call showSelect (sql)
	   if err <> 0 then echo "<br><font color=red>" & err.description & "</font>"
       ' response.end
    else
   		'如果非select语句,允许执行多条以分号分隔的语句
   		dim aSql,iLoop
   		aSql = split(sql,";")
   		for iLoop = 0 to UBound(aSql)
			if trim(aSql(iLoop)) <> "" then
      	    	conn.execute (aSql(iLoop))
				if err <> 0 then
					echo "<br><font color=red>" & err.description & "<br>&nbsp;&nbsp;<b>"
					echo iLoop + 1 & "、</b></font><font color=#CC6600>" & aSql(iLoop) & "</font><br>"
					'err.clear()     '忽略错误
					exit sub          '中止执行
				else
					echo "<div style='padding:3px 0px;border-bottom:1px solid #069;'><b>" & iLoop + 1 & "、</b>" & aSql(iLoop) & "</div>"
				end if
			end if
        next
        echo "<font color=red><h4>命令执行成功</h4></font>"
   end if
end sub

'==================================================================修改表名或字段名
sub reobj()
	on error resume next
	Dim mydb,mytable,tablename
	tablename = request("tablename")
	Set mydb = Server.CreateObject("ADOX.Catalog")
	mydb.ActiveConnection = conn
		
	if request("obj") = "field" then   '修改字段名
		dim fieldsname,newfieldsname
		fieldsname = request("fieldsname")
		newfieldsname = request("newfieldsname")
		Set mytable = Server.CreateObject("ADOX.Table")
		Set mytable = mydb.Tables(tablename) 
		mytable.Columns(fieldsname).Name = newfieldsname
	end if
	
	if request("obj") = "table" then   '修改表名
		dim newtablename
		newtablename = request("newtablename")
		mydb.Tables(tablename).Name = newtablename
	end if
	
	if err <> 0 then
		echo  err.description
		echo "<input type='button' name='ok' value=' 返 回 ' onClick='javascript:history.go(-1)'>"
		exit sub
	end if
	
	if request("obj") = "field" then
		response.Redirect "?key=view&table_name=" & tablename
	else
		response.Redirect "?key=view&table_name=" & newtablename
	end if
	
end sub

'==================================================================导出SQL
sub tosql(strt)
	'strt = 0 导出结构
	'strt = 1 导出内容
	dim strsql,objSchema,table
	if strt = "0"  then
		table = request("table_name")
		echo "以下是表 <font color=red>" & request("table_name") & "</font> 的结构: "
		echo "<input type='button' name='ok' value=' 返 回 ' onClick='javascript:history.go(-1)'>"
		strsql = getsql(table)
	end if
	if strt = "2" then
		echo "以下是 <font color=red> 数据库 </font> 的结构: "
		echo "<input type='button' name='ok' value=' 返 回 ' onClick='javascript:history.go(-1)'>"
		set objSchema = Conn.OpenSchema(adSchemaTables)
		Do While Not objSchema.EOF
			if objSchema("TABLE_TYPE") = "TABLE" then
				table = objSchema("TABLE_NAME")
				strsql = strsql & getsql(table)'table & "|"'getsql(table)
			end if
		objSchema.MoveNext
		Loop
		objSchema.close
	end if		
	echo "<textarea cols=110 rows=38>" & strsql & "</textarea>"
	conn.close
end sub

'================================================================== 输出表结构
function getsql(table)
	on error resume next
	getsql = "-- " & table & " SQL" & chr(10)
	dim primary,primarykey
	Set primary = Conn.OpenSchema(adSchemaPrimaryKeys,Array(empty,empty,table))
	if primary("COLUMN_NAME") <> "" then
		primarykey = primary("COLUMN_NAME")
	end if
	
	primary.Close
	set primary = nothing
	
	tbl_struct = "CREATE TABLE [" & table & "] ( " & chr(10)
	sql = "SELECT * FROM " & table
	Set rs = Conn.Execute(sql)
	if err = 0 then
		for i = 0 to rs.fields.count-1
		   tbl_struct = tbl_struct & "[" & rs(i).name & "] "
		   typs = typ(rs(i).type)
		   if typs = "VARCHAR" or typs = "BINARY" or typs = "CHAR" then
			 tbl_struct = tbl_struct & typs & "(" & rs(i).definedsize & ")"
		   else
			 tbl_struct = tbl_struct & typs & " "
		   end if
		   attrib = rs(i).attributes
		   if (attrib and adFldIsNullable) = 0 then
			 tbl_struct = tbl_struct&" NOT NULL"
		   end if
		   if rs(i).Properties("ISAUTOINCREMENT") = True then
			 tbl_struct = tbl_struct & " IDENTITY"
		   end if
		   tbl_struct = tbl_struct & "," & chr(10)
		next
		if primarykey <> "" then
			tbl_struct = tbl_struct & "PRIMARY KEY ([" & primarykey & "]));"
		else
			len_of_sql = Len(tbl_struct)
			tbl_struct = Mid(tbl_struct,1,len_of_sql-2)
			tbl_struct = tbl_struct & ");"
		end if
	else
		tbl_struct = "CREATE TABLE [" & table & "];"
	end if
	getsql = getsql & tbl_struct & chr(10) & chr(10)
end function

sub help()
	echo "SQL 常用语句：<br><br>"
	echo "创建表：<br>"
	echo "CREATE TABLE [表名] (<br>"
	echo "[test1] int not null identity,<br>"
	echo "[test2] binary not null,<br>"
	echo "primary key ([test1]))<br><br>"
	echo "设置主键：ALTER TABLE [tablename] ADD PRIMARY KEY ([fieldname])<br><br>"
	echo "查询：select * from tablename where fieldname *** order by id desc<br><br>"
	echo "更新：update tanlename set fieldname = values,cn_name='values' where ID = 1<br><br>"
	echo "添加：insert into tanlename (fieldnam,fieldnam2)values (1,'values')<br><br>"
	echo "删除：delete from tanlename where fieldname = values<br><br>"
	echo "删除表：DROP TABLE 数据表名称<br><br>"
	echo "添加字段：ALTER TABLE [表名] ADD [字段名] NVARCHAR (50) NULL<br><br>"
	echo "删除字段：alter table [tablename] drop [fieldname]<br><br>"
	echo "修改字段：ALTER TABLE [表名] ALTER COLUMN [字段名] 类型(大小) NULL<br><br>"
	echo "新建约束：ALTER TABLE [表名] ADD CONSTRAINT 约束名 CHECK ([约束字段] <= '2000-1-1')<br><br>"
	echo "删除约束：ALTER TABLE [表名] DROP CONSTRAINT 约束名<br><br>"
	echo "新建默认值：ALTER TABLE [表名] ADD CONSTRAINT 默认值名 DEFAULT '51WINDOWS.NET' FOR [字段名]<br><br>"
	echo "删除默认值：ALTER TABLE [表名] DROP CONSTRAINT 默认值名<br><br>"
end sub
Function hr_1_f(txt)
	hr_1_f="field[" & txt & "]"
End Function
Function val(txt)
	val=""
	if easp.var(hr_1_f(txt))<>"" then
		val=easp.var(hr_1_f(txt))
	end if
	if easp.var(txt)<>"" then
		val=easp.var(txt)
	end if
End Function
sub vas(val,txt)
	easp.var(val)=txt
End sub
sub vas2(val,txt)
	easp.var(hr_1(val))=txt
End sub
Function sessionExpire()
	GetUrl=Easp.GetUrl("")
	if Easp.Str.IsIn(GetUrl, "login.asp")=true then

	elseif session("username")=""  then
		Response.Redirect("/dzps/src/views/user/login.asp")
	end if
end function
' ============================================
' 格式化时间(显示)
' 参数：n_Flag
' 1:"yyyy-mm-dd hh:mm:ss"
' 2:"yyyy-mm-dd"
' 3:"hh:mm:ss"
' 4:"yyyy年mm月dd日"
' 5:"yyyymmdd"
' 6:"yyyymmddhhmmss" 
' ============================================
Function Format_Time(s_Time, n_Flag)
 Dim y, m, d, h, mi, s
 Format_Time = ""
 If IsDate(s_Time) = False Then Exit Function
 y = cstr(year(s_Time))
 m = cstr(month(s_Time))
 If len(m) = 1 Then m = "0" & m
 d = cstr(day(s_Time))
 If len(d) = 1 Then d = "0" & d
 h = cstr(hour(s_Time))
 If len(h) = 1 Then h = "0" & h
 mi = cstr(minute(s_Time))
 If len(mi) = 1 Then mi = "0" & mi
 s = cstr(second(s_Time))
 If len(s) = 1 Then s = "0" & s
 Select Case n_Flag
 Case 1
  ' yyyy-mm-dd hh:mm:ss
  Format_Time = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
 Case 2
  ' yyyy-mm-dd
  Format_Time = y & "-" & m & "-" & d
 Case 3
  ' hh:mm:ss
  Format_Time = h & ":" & mi & ":" & s
 Case 4
  ' yyyy年mm月dd日
  Format_Time = y & "年" & m & "月" & d & "日"
 Case 5
  ' yyyymmdd
  Format_Time = y & m & d
 case 6
  'yyyymmddhhmmss
  format_time= y & m & d & h & mi & s
 case 7
	format_time=cstr(day(s_Time))
 End Select
End Function

Function hr_b(txt)
	hr_b=" like '%" & txt & "%' "
End Function

Function hr_b2(txt)
	hr_b2=" like '%" & val(txt) & "%' "
End Function
Function delLasts(txt)
	txt=left(txt,len(txt)-1)
	delLasts=txt
End Function
Function t_define(table_name2)
	dim sql,table_name,i,rs,txt,conn2,objSchema
	set conn2 = Easp.Db.GetConn
	set objSchema = conn2.OpenSchema(adSchemaTables)
	Do While Not objSchema.EOF
		if objSchema("TABLE_TYPE") = "TABLE" then
			table_name=objSchema("TABLE_NAME")
			if table_name2="" or table_name=table_name2 then
				sql = "SELECT * FROM [" & table_name & "] "
				Set rs = easp.db.sel(sql)
				if rs.fields.count<30 then
					For i = 0 to rs.fields.count-1
						txt = txt & rs(i).name & ","
					next
					txt=delLasts(txt)
					echo "'" & table_name & "=" & txt			
					echo "<br>"	
				end if
				txt=""
				rs.close
				set rs=nothing
			end if
		end if
		objSchema.MoveNext
	Loop
End Function

sub view(table_name)
	'table_name = 表名称
	dim rs,sql,table,primary,primarykey,i,editstr,typs
	' on error resume next
	table = table_name
	Set primary = Conn.OpenSchema(adSchemaPrimaryKeys,Array(empty, empty, table))
	if primary("COLUMN_NAME") <> "" then
		primarykey = primary("COLUMN_NAME")
	end if
	primary.Close
	Set primary = Nothing
	%>
                                            <script language="javascript">
                                                function table_delete() {
                                                    if (confirm("确认删除该记录吗？   该操作将不可撤销！！！"))
                                                        return true;
                                                    else
                                                        return false;
                                                }

                                                function updateTableName() {
                                                    if (confirm("确认修改表名吗？   该操作将不可撤销！！！")) {
                                                        var name = document.getElementById("newtablename").value;
                                                        location.href = '?key=reobj&obj=table&tablename=<%=table_name%>&newtablename=' + name;
                                                        return true;
                                                    } else
                                                        return false;
                                                }

                                                function updateFieldName() {
                                                    if (confirm("确认修改字段名吗？")) {
                                                        var fieldsname = document.getElementById("fieldsname").value;
                                                        var newfieldsname = document.getElementById("newfieldsname").value;
                                                        //alert(fieldsname);
                                                        location.href = '?key=reobj&obj=field&tablename=<%=table_name%>&fieldsname=' + fieldsname + '&newfieldsname=' + newfieldsname;
                                                        return true;
                                                    } else
                                                        return false;
                                                }

                                                function setprimarykey() {
                                                    if (confirm("确认设为主键吗？")) {
                                                        var keyname = document.getElementById("keyname").value;
                                                        location.href = '?key=sql&sql=ALTER TABLE [<%=table_name%>] ADD PRIMARY KEY ([' + keyname + '])';
                                                        return true;
                                                    } else
                                                        return false;
                                                }
                                            </script>
                                            <font color=red>表：
                                                <%=table_name%>
                                            </font>&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="刷新本页" onClick="javascript:location.reload()" class="layui-btn"><br><br>
                                            <% if request("key") = "editfidlevi" then call editfidlevi() %>
                                                <table width="600" border="0" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC" class="layui-table">
                                                    <tr>
                                                        <td width="125" height="20" align="center">字 段 名</td>
                                                        <td width="110" align="center">类 型</td>
                                                        <td width="83" align="center"> 设定大小</td>
                                                        <td width="48" align="center">允许空</td>
                                                        <td width="76" align="center">自动编号</td>
                                                        <td width="54" align="center">主键</td>
                                                        <td width="82" align="center">执行操作</td>
                                                    </tr>
                                                    <%
	sql = "SELECT * FROM [" & table_name & "] "
	Set rs = Conn.Execute(sql)
	if err = 0 then
		For i = 0 to rs.fields.count-1-rs.fields.count
		%>
                                                        <tr>
                                                            <td height="20" align="left">
                                                                <%=rs(i).name%>
                                                            </td>
                                                            <td align="left">
                                                                <%=typ(rs(i).type)%>
                                                            </td>
                                                            <td align="center">
                                                                <%=rs(i).definedsize%>
                                                            </td>
                                                            <td align="center">
                                                                <%=iif((rs(i).Attributes and adFldIsNullable)=0,"No","Yes")%>
                                                            </td>
                                                            <td align="center">
                                                                <%=iif(rs(i).Properties("ISAUTOINCREMENT") = True,"Yes","No")%>
                                                            </td>
                                                            <td align="center">
                                                                <%=iif(rs(i).name = primarykey,"Yes","No")%>
                                                            </td>
                                                            <td align="center">
                                                                <a href="?key=editfidlevi&fidle=<%=rs(i).name%>&table_name=<%=table_name%>&fidletype=<%=typ(rs(i).type)%>">修改</a>&nbsp;
                                                                <a href="?key=sql&sql=alter table [<%=table_name%>] drop [<%=rs(i).name%>];" onClick="return table_delete();">删除</a>
                                                            </td>
                                                        </tr>
                                                        <%
			editstr = editstr&"<option value='"&rs(i).name&"'>"&rs(i).name&"</option>"
		next
		%>
                                                </table>
                                                <br>
                                                <a href="?key=sql&sql=select * from <%=table_name%>&table_name=<%=table_name%>&primarykey=<%=primarykey%>" class="layui-btn">浏览表记录</a> &nbsp;

                                                <a href="?key=tosql&strt=0&table_name=<%=table_name%>" class="layui-btn">导出表结构</a> &nbsp;


                                                <a href="?key=sql&sql=DROP TABLE <%=table_name%>" onClick="return table_delete();" class="layui-btn">删除表</a> &nbsp;&nbsp;&nbsp;
                                                <div class="layui-input-inline">
                                                    <input type="text" id="newtablename" name="newtablename" size="20" value="<%=table_name%>" class="layui-input">
                                                </div>
                                                <input type="button" value="修改表名" onClick="updateTableName();" class="layui-btn">
                                                <br><br>
                                                <form class="layui-form" action="">
                                                    <%
	'判断是否有主键
	if primarykey = "" then
		echo "<font color=red>该表没有主键，执行操作可能会导致数据损坏或丢失。</font><br>"
		echo "你可以将："
%>
                                                        <div class="layui-input-inline">
                                                            <%
		echo "<select name='keyname' id='keyname'>"
		For i=0 to rs.fields.count-1
			echo "<option value=" & rs(i).name & ">" & rs(i).name & "</option>"
		next
		echo "</select>&nbsp;"
%>
                                                        </div>
                                                        <div class="layui-input-inline">
                                                            <%
		echo "<input type=button value=设为主键 onclick='setprimarykey();' class=""layui-btn"">"
%>
                                                        </div>
                                                        <%
		echo "<br><br>"
end if
%>

                                                            <div class="layui-input-inline">
                                                                <%
	'显示修改字段名
	echo "<select name='fieldsname' id='fieldsname'>"
	echo "<option value=''>选择字段</option>"
	echo editstr
	echo "</select> "
%>
                                                            </div>
                                                            <%
		echo "改名为 "  & chr(10)
		%>
                                                                <div class="layui-input-inline">
                                                                    <%
		echo "<input type='text' name='newfieldsname' id='newfieldsname' size='20' class=""layui-input""> "  & chr(10)
		%>
                                                                </div>
                                                                <%
		echo "<input type=button value=修改字段名 onclick='updateFieldName();' class=""layui-btn"">"
		echo "<br><br>"
	end if
	rs.close
	set rs = nothing
%>
                                                </form>
                                                <font color=red>增加字段：</font><br><br>
                                                <form action="?key=addfield" method="post" class="layui-form">
                                                    <table width="600" height="39" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC" class="layui-table">
                                                        <tr>
                                                            <td width="60" height="20" align="center">字段名</td>
                                                            <td width="50" height="20" align="center">类型</td>
                                                            <td width="58" height="20" align="center">设定大小</td>
                                                            <td width="64" height="20" align="center">允许空值</td>
                                                            <td width="66" height="20" align="center"> 自动编号</td>
                                                            <td width="60" height="20" align="center">可填值</td>
                                                            <td width="96" height="20" align="center">&nbsp;&nbsp;</td>
                                                        </tr>
                                                        <tr>
                                                            <td width="600" height="20" align="center">
                                                                <div class="layui-input-inline">
                                                                    <input type="text" name="fldname" autocomplete="off" class="layui-input">
                                                                </div>
                                                            </td>
                                                            <td width="190" height="20" align="center">
                                                                <% fieldtypelist(0) %>
                                                            </td>
                                                            <td width="158" height="20" align="center">
                                                                <div class="layui-input-inline">
                                                                    <input type="text" name="fldsize" autocomplete="off" class="layui-input">
                                                                </div>
                                                            </td>
                                                            <td width="194" height="20" align="center">
                                                                <input name="null" type="checkbox" value="ON" checked lay-skin="primary">
                                                            </td>
                                                            <td width="66" height="20" align="center">
                                                                <input type="checkbox" name="autoincrement" value="ON" lay-skin="primary">
                                                            </td>
                                                            <td width="260" height="20" align="center">
                                                                <div class="layui-input-inline">
                                                                    <input type="text" name="canValue" autocomplete="off" class="layui-input">
                                                                </div>
                                                            </td>
                                                            <td width="96" height="20" align="center">
                                                                <input type="hidden" name="table_name" value="<%=table_name%>">
                                                                <input type="submit" value="提交" class="layui-btn">
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </form>
                                                <%
end sub

'==================================================================构建创建表的SQL语句
sub create_a_table(table_name)
	dim sql,i,primarykey,primary,rs
	' on error resume next

	sql = "SELECT * FROM [" & table_name & "] "
	Set rs = Conn.Execute(sql)
	if err <> 0 then
		echo err.description
	end if
	Set primary = Conn.OpenSchema(adSchemaPrimaryKeys,Array(empty, empty, table_name))
	if primary("COLUMN_NAME") <> "" then
		primarykey = primary("COLUMN_NAME")
	end if
	primary.Close
	Set primary = Nothing

	sql = "CREATE TABLE ["&table_name & "_A" &"] ("
	For i = 0 to rs.fields.count-1
	   sql = sql & "[" & rs(i).name & "] " & typ(rs(i).type)
		  if rs(i).definedsize <> "" and instr(typ(rs(i).type),"Int")=0 then
			  sql = sql & "(" & rs(i).definedsize & ")"
		  end if
		  if (rs(i).Attributes and adFldIsNullable)=0 then
			  sql = sql & " not null"
		  end if
		  if rs(i).Properties("ISAUTOINCREMENT") = True then
			  sql = sql & " identity"
		  end if
		  sql = sql & ","
		  
		 ' if primarykey <> "" then
		    ' sql = sql & ","
		 ' end if
	next
	if primarykey<>"" then
	   sql=sql&" primary key (["&primarykey&"]) "
	else
		sql=left(sql,len(sql)-1)
	end if
	sql = sql & ")"
	sql = replace(sql,"()","")  '构建空表
	' echo sql
	response.redirect "?key=sql&sql=" & sql 
end sub
function fld_idx(flds)
	dim a_flds,arr_ub,i
	a_flds=split(flds,",")
	arr_ub=ubound(a_flds)
	for i=0 to arr_ub
		vas "idx_"&a_flds(i),cstr(i)		
	next 
end function

function ival(txt)
	ival=val("idx_" + txt)
end function

'==================================================================修改字段属性的界面
sub editfidlevi()
	dim sql,rs,i
	' on error resume next
	sql = "Select * From [" & request("table_name") & "]"
	set rs = conn.execute(sql)
	for i = 0 to rs.fields.count - 1
		if rs(i).name = request("fidle") then
		%>
                                                    <script LANGUAGE="JavaScript">
                                                        function validate(theForm) {
                                                            if (theForm.type.value == "") {
                                                                alert("请输入数据类型");
                                                                theForm.type.focus();
                                                                return (false);
                                                            }
                                                            return (true);
                                                        }
                                                    </script>
                                                    <font color=red>修改字段属性：</font>
                                                    <form action="?key=editfidle&fidle=<%=request(" fidle ")%>&table_name=<%=request("table_name ")%>" method="post" name=frm onSubmit="return validate(frm)">
                                                        <table width="600" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC" class="layui-table">
                                                            <tr>
                                                                <td width="60" height="20" align="center">字段名</td>
                                                                <td width="50" height="20" align="center">类型</td>
                                                                <td width="58" height="20" align="center">设定大小</td>
                                                                <td width="64" height="20" align="center">允许空值</td>
                                                                <td width="66" height="20" align="center">自动编号</td>
                                                                <td width="60" height="20" align="center">可填值</td>
                                                                <td width="96" height="20"></td>
                                                            </tr>
                                                            <tr>
                                                                <td width="60" height="20" align="center">
                                                                    <%=rs(i).name%>
                                                                </td>
                                                                <td width="50" height="20" align="center">
                                                                    <% fieldtypelist(request("fidletype")) %>
                                                                </td>
                                                                <td width="58" height="20"><input type="text" name="size" size="10"></td>

                                                                <td width="64" height="20" align="center">
                                                                    <input type="checkbox" name="null" value="null" <%=iif((rs(i).Attributes and adFldIsNullable)=0, "", " checked")%>>
                                                                </td>
                                                                <td width="66" height="20" align="center">
                                                                    <input type="checkbox" name="autoincrement" value="y" <%=iif(rs(i).Properties( "ISAUTOINCREMENT")=True, " checked", "")%>>
                                                                </td>
                                                                <td width="60" height="20" align="center">
                                                                    <input type="text" name="canValue" size="10">
                                                                </td>
                                                                <td width="96" height="20" align="center">
                                                                    <input type="submit" name="Submit" value="提交" class="layui-btn">
                                                                </td>
                                                            </tr>
                                                        </table><br>
                                                    </form>
                                                    <%
		end if
	next
end sub

function rs2arr(rs)

end function
sub conci_del(numb)
	dim rs1,strdel,arr,i
	
	dim objSchema,table_name,primarykey
	set objSchema = Conn2.OpenSchema(adSchemaTables)
	Do While Not objSchema.EOF
		if objSchema("TABLE_TYPE") = "TABLE" then
			table_name=objSchema("TABLE_NAME")
			strdel = "delete from " & table_name & " where numb ='" & numb &"'"
			Easp.Db.Execute conn2,strdel
		end if
		objSchema.MoveNext
	Loop
	
	set rs1 = Easp.Db.Sel("select distinct tn from [bi0] where dbName={dbName} order by tn")
	
	' Do While Not rs1.EOF		
		' strdel = "delete from " & rs1("tn") & " where numb ='" & numb &"'"
		' Easp.Db.Execute conn2,strdel
		' rs1.MoveNext
	' Loop
	' Easp.Db.Close rs1
end sub


function extable(fn)
	dim objSchema,table_name,flag
	set objSchema = Conn2.OpenSchema(adSchemaTables)
	flag=0
	Do While Not objSchema.EOF
		if objSchema("TABLE_TYPE") = "TABLE" then
			table_name=objSchema("TABLE_NAME")
			if table_name = fn then
				flag=1
			end if
		end if
		objSchema.MoveNext
	Loop
	extable=flag
end function

function sextable()
	dim objSchema,table_name,txt
	set objSchema = Conn2.OpenSchema(adSchemaTables)
	Do While Not objSchema.EOF
		if objSchema("TABLE_TYPE") = "TABLE" then
			table_name=objSchema("TABLE_NAME")
			txt=txt&da(table_name)&","
		end if
		objSchema.MoveNext
	Loop
	txt=left(txt,len(txt)-1)
	sextable=txt
end function

sub conci()
	dim rs1,tablename,sql,rs2,arr,i,txt
	txt=" and tn in (" & sextable & ")"

	tablename = Easp.Db.Sel("select distinct tn from [bi0] where dbName={dbName} " & txt & " order by tn")("tn")
	vas "tablename",tablename
    
	set rs1 = Easp.Db.Sel("select distinct tn from [bi0] where dbName={dbName} "& txt & " order by tn")
	set rs2 = Easp.Db.Select(conn2, "select numb from {=tablename}")
	if rs2.recordCount >=1 then
		arr = rs2.GetRows
		Do While Not rs1.EOF		
			if extable(rs1("tn"))=1 then 
				vas "tablename",rs1("tn")
				for i=0 to ubound(arr,2)
					vas "numb",arr(0,i)
					Set rs2 = Easp.Db.Execute(conn2, "Select count(*) From {=tablename} where numb = {numb}")		
					if rs2(0) = 0 then
						sql= cr(val("tablename"),"numb")
						rs2 = Easp.Db.Execute(conn2, sql)					
					end if
				next 
			end if
			rs1.MoveNext
		Loop		
	else
	end if
	Easp.Db.Close rs1
	Easp.Db.Close rs2
end sub
sub temp
	dim ret,rs1,sql
	' ret= Easp.Db.Del("[bi0]", "1=1")
	sql = "select numb from baseinfo3 where mode='inputman' and f1="& da(session("username"))
	set rs1=easp.db.sel(sql)	
	' set rs1 = Easp.Db.Sel("select distinct tn from [bi0] where dbName={dbName} order by tn")	
	Do While Not rs1.EOF
		echo rs1(0) & "<br>"
		rs1.MoveNext
	loop
	' ret= Easp.Db.Del("[bi0]", "tn='追风透骨胶囊治疗骨关节炎的上市后再评价'")
	' echo ret
end sub

function look_arr(arr,fld)
	dim i,tmp
	tmp=""
	for i=0 to ubound(arr,2)
		if arr(0,i)=fld then
			tmp=arr(1,i)
			exit for
		end if
	next
	look_arr=tmp
end function

function input_h(name)
	dim txt,i
	txt=split(name,",")
	for i=0 to ubound(txt)
		i_h txt(i),val(txt(i))
	next
end function

function hi(name,value)
	i_h name,value
end function
function i_h(name,value)
	dim txt
	txt="<input type='hidden' class='layui-input' id='[name]' name='[name]' value='[value]' >"
	txt=replace(txt,"[name]",name)
	txt=replace(txt,"[value]",value)
	response.write txt
end function
function cb(name,title,checked)
	dim txt
	txt = "<input type='checkbox' id='[name]' name='[name]' lay-skin='primary' title='[title]' [checked]><div class='layui-unselect layui-form-checkbox' lay-skin='primary' ><span>[title]</span><i class='layui-icon layui-icon-ok'></i></div>"
	txt = replace(txt,"[name]",name)
	txt = replace(txt,"[title]",title)
	txt = replace(txt,"[checked]",checked)
	cb=txt
	response.write cb
end function

function inputman
	dim ret,rs1,sql,txt
	sql = "select numb from baseinfo3 where mode='inputman' and f1="& da(session("username"))
	set rs1=easp.db.sel(sql)	
	Do While Not rs1.EOF
		txt=txt&da(rs1(0))&","
		rs1.MoveNext
	loop
	if txt <>"" then 
		txt=left(txt,len(txt)-1)
	end if
	inputman=txt
end function
function qx_save2()
	dim sql,rs1,ret
	vas "username",val("usernameqx")
	sql="select * from [prj] where prn like '%" &  easp.var("dbName1") & "%' order by id desc"
	Set rs1 = Easp.Db.Sel(sql)
	Easp.Db.del "t_qx","username={username}"
	Do While Not rs1.EOF		
		if val(hr_1(rs1("ID")))="on" then
			vas "t_db4qx_id",rs1("id")
			sql=cr("t_qx","username,t_db4qx_id,dbName")
			ret = Easp.Db.Exec(sql)
		end if
		rs1.MoveNext
	Loop
	ret3(ret)
end function
Function setv (name,rs1)
	if rs1.RecordCount>=1 then
		easp.var(name)=rs1(name)
	end if
End Function

sub binfo
	rdict_name1 "website","网站名称"
	rdict_name1 "webtitle","网站标题"
end sub
function rdict_name1(fieldn,name1)
	s1 "select name2 as " & fieldn & " from [baseinfo] where [name1]=" & da(name1)
end function
sub t_exp(tn)
	dim s,sql,filename,fs,myfile,x,strLine,rstData,strsql
	strSql="select * from " & tn
	Set fs = server.CreateObject("scripting.filesystemobject") 
	'--假设你想让生成的EXCEL文件做如下的存放 
	filename = Server.MapPath("\dzps\file\xls\"& tn&".xls") 
	'--如果原来的EXCEL文件存在的话删除它 
	if fs.FileExists(filename) then 
	   fs.DeleteFile(filename) 
	end  if 
	'--创建EXCEL文件 
	set myfile = fs.CreateTextFile(filename,true) 
	Set rstData =easp.db.sel(strSql)
	if not rstData.EOF and not rstData.BOF then 
	   dim  trLine,responsestr 
	   strLine=""
	   For each x in rstData.fields 
		 strLine = strLine & x.name & chr(9) 
	   Next
	'--将表的列名先写入EXCEL 
	   myfile.writeline strLine 
	   Do while Not rstData.EOF 
		 strLine=""
		 for each x in rstData.Fields 
		   strLine = strLine & x.value &  chr(9) 
		 next 
		 myfile.writeline  strLine 
	  
		 rstData.MoveNext 
	   loop 
	end if 
	rstData.Close 
	set rstData = nothing
	' echo strLine
end sub

sub exp()
	dim rs1,i,ret
	dim rsArray,sql
	set rs1 = Easp.Db.Sel("select distinct tn from [bi0] where dbName={dbName} order by tn")
	i=0
	Do While Not rs1.EOF		
		i=i+1
		emp2(rs1("tn"))
		rs1.MoveNext
	Loop
	ret3("1")
end sub
Function clearSession()
	session("username")=""
	session("password")=""
End Function

Function startSession()
	Session.Timeout = 60
	session("user_id")=val("user_id")
	session("username")=val("username")
	session("password")=val("password")
	session("user_typ")=val("user_typ")
	session("mobile")=val("mobile")
End Function
Function c_prj_list(cid)
	dim sql,rs1,cnt
	sql="select * from [prj] "
	Set rs1 = Easp.Db.Sel(sql)
	vas "cid",cid
	Do While Not rs1.EOF		
		vas "pid",rs1("ID")
		sql="select count(id) from prj_c where cid={cid:int} and pid={pid:int} "
		cnt = Easp.Db.Sel(sql)(0)
		if cnt = 0 then
			cb rs1("ID"),rs1("prn"),""
		else
			cb rs1("ID"),rs1("prn"),"checked"
		end if
		rs1.MoveNext
	Loop
End Function
  function sql2arr2(sql)
	dim rs2,arr
	'Easp.Db.PageSize=200
	Set rs2 = Easp.Db.GetRS(sql)
	if rs2.recordCount >=1 then
		arr = rs2.GetRows	
	else
		redim arr(0)
	end if
	rs2.Close 
	set rs2 = nothing
	sql2arr2=arr
end function

function sql2arr(sql)
	dim rs2,arr
	set rs2 = Easp.Db.Sel(sql)
	if rs2.recordCount >=1 then
		arr = rs2.GetRows	
	else
		redim arr(0)
	end if
	rs2.Close 
	set rs2 = nothing
	sql2arr=arr
end function
sub g_tbf(field,title)
	dim fielda,titlea,i,tmp
	fielda=split(field,",")
	titlea=split(title,",")
	for i=0 to ubound(fielda)
		if replace(fielda(i),":","")<>fielda(i) then
			tmp=split(fielda(i),":")
			fielda(i)=tmp(0)
			xx_1 fielda(i),titlea(i),tmp(1)
		elseif replace(titlea(i),":","")<>titlea(i) then
			tmp=split(titlea(i),":")
			titlea(i)=tmp(0)
			xx_1 fielda(i),titlea(i),tmp(1)	
		else
			xx_1 fielda(i),titlea(i),"100"
			'Easp.Echo js3("tb1.js",fielda(i),titlea(i),"width:100")
		end if
	next
end sub
sub xx_1(field,title,tmp)
	if tmp="0" then
		Easp.Echo js3("tb1.js",field,title,"hide:true")
	else
		Easp.Echo js3("tb1.js",field,title,"width:" & tmp)			
	end if
end sub
Function js3(fn,field,title,width) 
	dim txt
	txt="{field: '[dy:field]',title: '[dy:title]',100},	"
	txt=replace(txt,"[dy:field]",field)
	txt=replace(txt,"[dy:title]",title)
	if width<>"" then 
		txt=replace(txt,"100",width)
	end if
	js3=txt
	' Easp.Echo txt
End Function
sub xl()
	dim rs2,arr
	set rs2 = Easp.Db.Sel("select id,prn from prj")
	if rs2.recordCount >=1 then
		arr = rs2.GetRows	
		echo myopt2("prj_id","所属项目",arr,iif(val("prj_id") = "",0,val("prj_id")))
	end if
end sub

function blockquote(txt)
	echo "<blockquote class='layui-elem-quote'>"
	echo txt
	echo "</blockquote>"
end function

function blockquote2(txt)
	echo "<blockquote class='layui-elem-quote layui-quote-nm'>"
	echo txt
	echo "</blockquote>"
end function

function colla(title,content)
	dim txt
	txt=txt&  "<div class='layui-colla-item'>"
    txt=txt&  "<h2 class='layui-colla-title'>"& title &"</h2>"  
    txt=txt&  "<div class='layui-colla-content'>"
    txt=txt&  content
    txt=txt& "</div>"
	txt=txt& "</div>"	
	colla=txt				
end function
function z_cb(name,title)
	'该函数是否继续使用,存疑，
	dim txt
	txt = "<input type='checkbox' name='[name]' lay-skin='primary' title='[title]'><div class='layui-unselect layui-form-checkbox' lay-skin='primary'><span>[title]</span><i class='layui-icon layui-icon-ok'></i></div>"
	txt = replace(txt,"[name]",name)
	txt = replace(txt,"[title]",title)
	z_cb=txt
	response.write txt
end function

function input2(name,placeholder)
dim txt
	txt="<div class='layui-form-item'>"
	txt=txt&"<input type='text' class='layui-input' id='[name]' name='[name]' placeholder='[placeholder]'>"
	txt=replace(txt,"[name]",name)
	txt=replace(txt,"[placeholder]",placeholder)
	txt=txt&"</div>"
	response.write txt

end function

function input(name,placeholder)
	dim txt
	txt="<input type='text' class='layui-input' id='[name]' name='[name]' placeholder='[placeholder]'>"
	txt=replace(txt,"[name]",name)
	txt=replace(txt,"[placeholder]",placeholder)
	response.write txt
end function

%>